package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.SvarPageDto;
import com.wizz.trade.information.entity.Svar;
import com.wizz.trade.information.mapper.SvarMapper;
import com.wizz.trade.information.service.SvarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 仓库签约品种表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class SvarServiceImpl extends ServiceImpl<SvarMapper, Svar> implements SvarService {

    @Resource
    private SvarMapper svarMapper;

    @Override
    public void addSvar(Svar svar) {
        svarMapper.insert(svar);
    }

    @Override
    public void updateSvar(Svar svar) {
        svarMapper.updateById(svar);
    }

    @Override
    public void deleteSvar(Integer id) {
        svarMapper.deleteById(id);
    }

    @Override
    public PageVo<Svar> getPage(SvarPageDto svarPageDto) {
        LambdaQueryWrapper<Svar> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(!Objects.isNull(svarPageDto.getSta()),Svar::getSta, svarPageDto.getSta());
        queryWrapper.eq(!Objects.isNull(svarPageDto.getGrad()),Svar::getGrad, svarPageDto.getGrad());
        IPage<Svar> page = svarMapper.selectPage(PageUtil.initPage(svarPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Svar> getAll() {
        return svarMapper.selectList(null);
    }
}
